package com.zusmart.core.config.data;

import java.text.SimpleDateFormat;
import java.util.Date;

import com.zusmart.core.config.support.AbstractConfigDataConverter;

public class ConfigDataConverterForDate extends AbstractConfigDataConverter<Date> {

	private final SimpleDateFormat SIMPLE_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
	private final SimpleDateFormat SIMPLE_DATETIME_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

	@Override
	public Class<Date> getSupportClass() {
		return Date.class;
	}

	@Override
	protected Date doConvert(String value) throws Exception {
		if (value.length() <= 10) {
			return this.SIMPLE_DATE_FORMAT.parse(value);
		} else {
			return this.SIMPLE_DATETIME_FORMAT.parse(value);
		}
	}

}